home *** CD-ROM | disk | FTP | other *** search
/ Mixa 155: Dogs / MIXA 155: Dogs.iso / pc / Viewer / BROWSER(W) / フィルタ / PDF / LIB / gs_cff.ps < prev    next >
Encoding:
Text File  |  2002-10-29  |  20.8 KB  |  739 lines

  1. %    Copyright (C) 1997, 1998, 1999, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile: gs_cff.ps,v $ $Revision: 1.10 $
  6. % Loader for CFF (compressed) fonts, including OpenType CFFs.
  7. % The following are not implemented yet:
  8. %    Deleted entries in the Name Index
  9. %    Embedded PostScript
  10. %    Multiple Master fonts
  11. %    Chameleon fonts
  12. %    Synthetic fonts
  13.  
  14. % ---------------- Font loading machinery ---------------- %
  15.  
  16. % Augment the FONTPATH machinery so it recognizes OpenType CFF font sets.
  17.  
  18. /.scanfontheaders where {
  19.   pop /.scanfontheaders [
  20.    .scanfontheaders aload pop (OTTO*)
  21.   ] def
  22. } if
  23.  
  24. % Load a font file that might be an OpenType CFF font set.
  25.  
  26. % <file> .loadfontfile -
  27. /.loadnonottofontfile /.loadfontfile load def
  28. /.loadfontfile {
  29.   dup 4 string .peekstring pop (OTTO) eq {
  30.         % If this is a font at all, it's an OpenType CFF font set.
  31.     .loadottofontfile
  32.   } {
  33.         % Not a TrueType font.
  34.     .loadnonottofontfile
  35.   } ifelse
  36. } bind def
  37.  
  38. % <file> .loadottofontfile -
  39. /.loadottofontfile {
  40.   /FontSetInit /ProcSet findresource begin
  41.   2 dict begin
  42.   /f exch def /cff null def
  43.   card32 pop card16 6 { next pop } repeat dup {
  44.         % Stack: numtables tablesleft
  45.     dup 0 eq {
  46.       pop pop /.loadottofontfile cvx /invalidfont signalerror
  47.     } if
  48.     f 4 string readstring pop (CFF ) eq { sub exit } if
  49.     1 sub
  50.   } loop
  51.         % Stack: tablesread
  52.   card32 pop card32 card32
  53.         % Stack: tablesread start length
  54.   exch 3 -1 roll 1 add 16 mul 12 add sub
  55.   f exch subfilefilter flushfile    % skip to start
  56.   f exch subfilefilter end
  57.     % Use a random FontSet resource name.  ****** WRONG ******
  58.   realtime rand xor =string cvs exch false
  59.   ReadData
  60. } bind def
  61.  
  62. 30 dict begin
  63.  
  64. % ---------------- Standard strings (actually names) ---------------- %
  65.  
  66. /StandardStrings mark
  67.     % The initial StandardStrings that that denote characters are
  68.     % defined as a pseudo-Encoding.
  69. % 0
  70.   /CFFStandardStrings .findencoding aload pop
  71. % 379
  72.   (001.000)
  73. % 380
  74.   (001.001) (001.002) (001.003) /Black /Bold
  75.   /Book /Light /Medium /Regular /Roman
  76.   /Semibold
  77. .packtomark def
  78.  
  79. % ---------------- Standard encodings ---------------- %
  80.  
  81. /StandardEncodings [
  82.  
  83. % StandardEncoding
  84. mark
  85.   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  86.   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  87.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  88.   17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  89.   33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  90.   49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  91.   65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  92.   81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 0
  93.   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94.   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95.   0 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  96.   0 111 112 113 114 0 115 116 117 118 119 120 121 122 0 123
  97.   0 124 125 126 127 128 129 130 131 0 132 133 0 134 135 136
  98.   137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99.   0 138 0 139 0 0 0 0 140 141 142 143 0 0 0 0
  100.   0 144 0 0 0 145 0 0 146 147 148 149 0 0 0 0
  101. .packtomark
  102.  
  103. % ExpertEncoding
  104. mark
  105.   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  106.   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  107.   1 229 230 0 231 232 233 234 235 236 237 238 13 14 15 99
  108.   239 240 241 242 243 244 245 246 247 248 27 28 249 250 251 252
  109.   0 253 254 255 256 257 0 0 0 258 0 0 259 260 261 262
  110.   0 0 263 264 265 0 266 109 110 267 268 269 0 270 271 272
  111.   273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
  112.   289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 0
  113.   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114.   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  115.   0 304 305 306 0 0 307 308 309 310 311 0 312 0 0 313
  116.   0 0 314 315 0 0 316 317 318 0 0 0 158 155 163 319
  117.   320 321 322 323 324 325 0 0 326 150 164 169 327 328 329 330
  118.   331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
  119.   347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
  120.   363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
  121. .packtomark
  122.  
  123. ] readonly def
  124.  
  125. % ---------------- Standard Charsets ---------------- %
  126.  
  127. % We include an explicit 0 at the beginning of each charset.
  128.  
  129. /StandardCharsets [
  130.  
  131. % ISOAdobe
  132. mark
  133.   0
  134.   1 1 228 { } for
  135. .packtomark
  136.  
  137. % Expert
  138. mark
  139.   0
  140.   1 229 230 231 232 233 234 235 236 237 238 13 14 15 99 239
  141.   240 241 242 243 244 245 246 247 248 27 28 249 250 251 252 253
  142.   254 255 256 257 258 259 260 261 262 263 264 265 266 109 110 267
  143.   268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
  144.   284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
  145.   300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
  146.   316 317 318 158 155 163 319 320 321 322 323 324 325 326 150 164
  147.   169 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
  148.   342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
  149.   358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
  150.   374 375 376 377 378
  151. .packtomark
  152.  
  153. % ExpertSubset
  154. mark
  155.   0
  156.   1 231 232 235 236 237 238 13 14 15 99 239 240 241 242 243
  157.   244 245 246 247 248 27 28 249 250 251 253 254 255 256 257 258
  158.   259 260 261 262 263 264 265 266 109 110 267 268 269 270 272 300
  159.   301 302 305 314 315 158 155 163 320 321 322 323 324 325 326 150
  160.   164 169 327 328 329 330 331 332 333 334 335 336 337 338 339 340
  161.   341 342 343 344 345 346
  162. .packtomark
  163.  
  164. ] readonly def
  165.  
  166. % ---------------- Font loading ---------------- %
  167.  
  168. % ------ Utilities ------ %
  169.  
  170. /advance {    % <n> advance -
  171.   f cff eq { pos add /pos exch store } { pop } ifelse
  172. } bind def
  173. /next {        % - next <byte>
  174.   f read {
  175.     1 advance
  176.     DEBUG { (  ) print dup = } if
  177.   } if
  178. } bind def
  179. /next2 {    % - next2 <byte1> <byte2>
  180.   f read {
  181.     f read {
  182.       2 advance
  183.       DEBUG { (  ) print 1 index =only (,) print dup = } if
  184.     } {
  185.       1 advance
  186.       DEBUG { (  ) print dup = } if
  187.     } ifelse
  188.   } if
  189. } bind def
  190. /nextstring {    % <length> nextstring <string>
  191.   dup 0 eq {
  192.     pop ()
  193.   } {
  194.     string f exch readstring pop dup length advance
  195.     DEBUG { (  ) print dup == } if
  196.   } ifelse
  197. } bind def
  198. /card8        % - card8 <card8>
  199.  /next load
  200. def
  201. /card16 {    % - card16 <card16>
  202.   next2 exch 8 bitshift add
  203. } bind def
  204. /card32 {    % - card32 <card32>
  205.   card16 16 bitshift card16 add
  206. } bind def
  207. /offsetprocs [
  208.   /card8 load
  209.   /card16 load
  210.   { card8 16 bitshift card16 add } bind
  211.   /card32 load
  212. ] readonly def
  213. /offsetproc {    % <offsize> offsetproc <proc>
  214.   1 sub //offsetprocs exch get
  215. } bind def
  216. /offset {    % <offsize> offset <offset>
  217.   offsetproc exec
  218. } bind def
  219. /sid        % - <sid> sid
  220.   /card16 load
  221. def
  222. /Index {    % - Index <array>
  223.   mark card16 dup 0 ne {
  224.     1 exch next offsetproc dup exec pop exch {
  225.       dup exec dup 4 -1 roll sub 3 1 roll exch
  226.     } repeat pop
  227.   } if pop .packtomark
  228.   [ exch { nextstring } forall ] readonly
  229. } bind def
  230. /tokens {    % - tokens <num1> ... <op#> (op# = 12 means EOF)
  231.   {
  232.     f read not { 12 exit } if
  233.     DEBUG { (..) print dup = } if
  234.     1 advance
  235.     dup 12 eq { pop next 32 add exit } if
  236.     dup 28 lt { exit } if
  237.     dup 32 lt {
  238.       28 sub {
  239.     { card16 32768 xor 32768 sub }
  240.     { 4 offset dup 16#7fffffff gt { -1 32 bitshift add } if }
  241.     { tokenreal }
  242.     { 31 exit }
  243.       } exch get exec
  244.     } {
  245.       dup 247 lt {
  246.     139 sub
  247.       } {
  248.     247 sub {
  249.       { next 108 add }
  250.       { next 364 add }
  251.       { next 620 add }
  252.       { next 876 add }
  253.       { next 108 add neg }
  254.       { next 364 add neg }
  255.       { next 620 add neg }
  256.       { next 876 add neg }
  257.       % 255 is deliberately omitted and will cause a rangecheck
  258.     } exch get exec
  259.       } ifelse
  260.     } ifelse
  261.   } loop
  262. } bind def
  263. /tokenbuf 100 string def
  264. /tokenput {    % <index> <char> tokenput <index+1>
  265.   tokenbuf 2 index 3 -1 roll put 1 add
  266. } bind def
  267. /tokenrealarray [
  268.  (0123456789.E) { } forall
  269.  [(E) 0 get /tokenput cvx (-) 0 get] cvx
  270.  null        % will give an error
  271.  (-) 0 get
  272.  { exit }
  273. ] readonly def
  274. /tokenreal {    % - tokenreal <float>
  275.   0 {
  276.     next exch 1 index -4 bitshift tokenrealarray exch get exec tokenput
  277.         % We must leave the byte on the stack temporarily so that
  278.         % the exit will see a consistent stack state.
  279.     1 index 15 and tokenrealarray exch get exec tokenput exch pop
  280.   } loop
  281.   tokenbuf 0 3 -1 roll getinterval cvr exch pop
  282. } bind def
  283. /Dict {        % <opsdict> Dict -
  284.   /opdict exch store {
  285.     mark tokens
  286.     DEBUG { (tokens: ) print ] dup === mark exch aload pop } if
  287.     opdict exch .knownget { exec } if cleartomark
  288.   } loop cleartomark
  289. } bind def
  290. /idstring {    % <sid> idstring <string|name>
  291.   dup 391 lt { //StandardStrings } { 391 sub strings } ifelse exch get
  292. } bind def
  293. /idname {    % <sid> idname <name>
  294.   idstring dup type /nametype ne { cvn } if
  295. } bind def
  296. /subfilefilter {    % <file> <length> subfilefilter <filter>
  297.     % SubFileDecode interprets a length of 0 as infinite.
  298.   dup 0 le { pop pop () 0 } if () /SubFileDecode filter
  299. } bind def
  300.  
  301. % ------ Top dictionary ------ %
  302.  
  303. /offput {    % <offset> <proc> offput -
  304.   DEBUG { (queued: ) print 1 index =only ( ) print dup === } if
  305.   currentdict exch aload length 1 add packedarray cvx
  306.   offsets 3 1 roll put
  307. } bind def
  308. /queueput {    % <font> <proc> queueput -
  309.   16#7fffffff offsets { pop .min } forall
  310.   pos sub nextstring
  311.   3 1 roll aload length 2 add packedarray cvx
  312.   [ queued aload pop counttomark 2 add -1 roll ]
  313.   /queued exch store
  314. } bind def
  315. /xxput {    % <value> <key> <dict> xxput -
  316.   3 1 roll exch put
  317. } bind def
  318. /putfi {    % <value> <key> putfi -
  319.   FontInfo xxput
  320. } bind def
  321. /xdef {        % <value> <key> xdef -
  322.   exch def
  323. } bind def
  324. /topdictops mark
  325.   12 { exit }
  326.   0 { idstring /version putfi }
  327.   1 { idstring /Notice putfi }
  328.   32 { idstring /Copyright putfi }
  329.   2 { idstring /FullName putfi }
  330.   3 { idstring /FamilyName putfi }
  331.   4 { idstring /Weight putfi }
  332.   33 { 0 ne /isFixedPitch putfi }
  333.   34 { /ItalicAngle putfi }
  334.   35 { /UnderlinePosition putfi }
  335.   36 { /UnderlineThickness putfi }
  336.   37 { /PaintType xdef }
  337.   38 { /FontType xdef }        % actually CharstringType
  338.   39 { counttomark array astore /FontMatrix xdef }
  339.   13 { /UniqueID xdef }
  340.   5 { counttomark array astore /FontBBox xdef }
  341.   40 { /StrokeWidth xdef }
  342.   14 { counttomark array astore /XUID xdef }
  343.   15 {
  344.     dup StandardCharsets length lt {
  345.       StandardCharsets exch get /charset xdef
  346.     } {
  347.       { queuecharset } offput
  348.     } ifelse
  349.   }
  350.   16 {
  351.     dup StandardEncodings length lt {
  352.       /Encoding xdef
  353.     } {
  354.       { queueEncoding } offput
  355.     } ifelse
  356.   }
  357.   17 { { readCharStrings } offput }
  358.   18 { exch /readPrivate cvx 2 packedarray offput }
  359.     % CIDFont operators
  360.   62 {        % ROS, must be first in a CIDFont
  361.     currentdict /FontType undef
  362.     currentdict /Private undef
  363.     currentdict /Encoding undef
  364.     currentdict /FontMatrix undef
  365.     /CIDFontVersion 0 def
  366.     /CIDFontRevision 0 def
  367.     /CIDFontType 0 def
  368.     /CIDCount 8720 def
  369.     3 dict begin
  370.     /Supplement xdef
  371.     idstring /Ordering xdef
  372.     idstring /Registry xdef
  373.     /CIDSystemInfo currentdict end def
  374.   }
  375.   63 { /CIDFontVersion xdef }
  376.   64 { /CIDFontRevision xdef }
  377.   65 { /CIDFontType xdef }
  378.   66 { /CIDCount xdef }
  379.   67 { /UIDBase xdef }
  380.   68 { { readFDArray } offput }
  381.   69 { { readFDSelect } offput }
  382.     % This operator only appears in a FDArray element.
  383.   70 { idstring /FontName exch def }
  384. .dicttomark readonly def
  385.  
  386. % readcharset and readFDSelect may require the length of CharStringArray,
  387. % but these structures may occur in the file before the CharStrings.
  388. % If that happens, use a hack: assume that all the data up to the next
  389. % queued read should be read.
  390.  
  391. /charstringcount {    % <font> charstringcount <count> true
  392.             % <font> charstringcount <length> false
  393.   /CharStringArray .knownget {
  394.     length true
  395.   } {
  396.     % Hack: look for the next queued read.
  397.     16#7fffffff offsets { pop .min } forall
  398.     pos sub false
  399.   } ifelse
  400. } bind def
  401.  
  402. /readCharStrings {    % <font> readCharStrings -
  403.   /CharStringArray Index put
  404. } bind def
  405.  
  406. % ------ Charsets and encodings ------ %
  407.  
  408. % Note: formats 1 and 2 can overflow the operand stack.
  409. % We'll fix this if it ever becomes necessary.
  410. /charsetcount {
  411.   charstringcount { 1 sub } { 2 idiv } ifelse
  412. } bind def
  413. /charsetformats [
  414. { [ 0 3 -1 roll charsetcount { sid } repeat ]
  415. } bind
  416. { [ 0 3 -1 roll charsetcount {
  417.     dup 0 eq { pop exit } if
  418.     sid card8 1 add 2 index .min { exch 1 sub 1 index 1 add } repeat pop
  419.   } loop ]
  420. } bind
  421. { [ 0 3 -1 roll charsetcount {
  422.     dup 0 eq { pop exit } if
  423.     sid card16 1 add 2 index .min { exch 1 sub 1 index 1 add } repeat pop
  424.   } loop ]
  425. } bind
  426. ] readonly def
  427. /queuecharset {        % <font> queuecharset -
  428.   { readcharset } queueput
  429. } bind def
  430. /readcharset {        % <data> <font> readcharset -
  431.   begin 0 () /SubFileDecode filter /f exch store
  432.   charsetformats next get currentdict exch exec /charset exch def end
  433. } bind def
  434.  
  435. /encodingformats [
  436. { 1 1 next { next exch Encoding 3 1 roll put } for
  437. } bind
  438. { 1 next {
  439.     next next 1 add {
  440.             % Stack: gid code
  441.       Encoding 1 index 3 index put
  442.       exch 1 add exch 1 add
  443.     } repeat pop
  444.   } repeat pop
  445. } bind
  446. ] readonly def
  447. /queueEncoding {    % <font> queueEncoding -
  448.   { readEncoding } queueput
  449. } bind def
  450. /readEncoding {        % <data> <font> readEncoding -
  451.   begin 0 () /SubFileDecode filter /f exch store
  452.   /Encoding [ 256 { /.notdef } repeat ] def
  453.   next encodingformats 1 index 127 and get exec
  454.   128 ge {
  455.             % Read supplementary encodings.
  456.     next {
  457.       Encoding next sid idname put
  458.     } repeat
  459.   } if end
  460. } bind def
  461.  
  462. % ------ FDArray and FDSelect ------ %
  463.  
  464. /readFDArray {        % <font> readFDArray -
  465.   Index exch
  466.   2 dict begin /f null def begin
  467.   [ exch {
  468.     dup length subfilefilter /f exch store
  469.     10 dict begin
  470.     /FontType 2 def
  471.     /PaintType 0 def
  472.     /FontMatrix [0.001 0 0 0.001 0 0] def
  473.     /Private 20 dict def
  474.     //topdictops Dict currentdict end
  475.   } forall ] /FDArray xdef end end
  476. } bind def
  477.  
  478. % Note: this implementation can overflow the operand stack.
  479. % We'll fix this if it ever becomes necessary.
  480. /fdselectformats [
  481. { [ exch charstringcount pop { card8 } repeat ] } bind
  482. { /FDSelect cvx /invalidfont signalerror } bind
  483. dup
  484. { pop [ card16 card16 exch {
  485.         % Stack: previndex
  486.     card8 card16 dup 4 1 roll 3 -1 roll sub 1 sub {
  487.       exch 1 index
  488.     } repeat exch
  489.   } repeat pop ]
  490. } bind
  491. ] readonly def
  492.  
  493. /readFDSelect {        % <font> readFDSelect -
  494.   begin fdselectformats next get currentdict exch exec /FDSelect exch def end
  495. } bind def
  496.  
  497.  
  498. % ------ Private dictionary ------ %
  499.  
  500. /deltarray {        % -mark- <num1> ... deltarray <num1'> ...
  501.   0 counttomark 1 sub { counttomark -1 roll add dup } repeat pop
  502.   counttomark array astore
  503. } bind def
  504.  
  505. /privatedictops mark
  506.   12 { exit }
  507.   6 { deltarray /BlueValues xdef }
  508.   7 { deltarray /OtherBlues xdef }
  509.   8 { deltarray /FamilyBlues xdef }
  510.   9 { deltarray /FamilyOtherBlues xdef }
  511.   41 { /BlueScale xdef }
  512.   42 { /BlueShift xdef }
  513.   43 { /BlueFuzz xdef }
  514.   10 { 1 array astore /StdHW xdef }
  515.   11 { 1 array astore /StdVW xdef }
  516.   44 { deltarray /StemSnapH xdef }
  517.   45 { deltarray /StemSnapV xdef }
  518.   46 { 0 ne /ForceBold xdef }
  519.   47 { /ForceBoldThreshold xdef }
  520.   48 { /lenIV xdef }
  521.   49 { /LanguageGroup xdef }
  522.   50 { /ExpansionFactor xdef }
  523.   51 { /initialRandomSeed xdef }
  524.   19 { PrivateStart add { readSubrs } offput }
  525.   20 { /defaultWidthX xdef }
  526.   21 { /nominalWidthX xdef }
  527.     % Multiple Master fonts only
  528.   59 { /NDV xdef }
  529.   60 { /CDV xdef }
  530.   61 { /lenBuildCharArray xdef }
  531. .dicttomark readonly def
  532.  
  533. /readPrivate {        % <font> <size> readPrivate -
  534.   2 dict begin
  535.   /PrivateStart pos def
  536.   f 3 1 roll exch 1 index f exch subfilefilter /f exch store
  537.   dup /FontType get exch
  538.   /Private get begin
  539.         % Default lenIV to -1 even for Type 1 CharStrings.
  540.   2 ne { /lenIV -1 def } if
  541.   //privatedictops Dict end
  542.   exch /f exch store advance
  543.   end
  544. } bind def
  545.  
  546. /readSubrs {        % <font> readSubrs -
  547.   /Subrs Index put
  548. } bind def
  549.  
  550. % ------ Main program ------ %
  551.  
  552. % Clean up after finishing a font.
  553. /cleanupFont {        % (currentdict) cleanupFont -
  554.         % Remove unwanted entries.
  555.   currentdict /charset undef
  556.   currentdict /CharStringArray undef
  557. } bind def
  558.  
  559. % Update the Encoding and CharStrings for a real font.
  560. /finishFont {        % (currentdict) finishFont -
  561.         % Construct the real Encoding.
  562.         % The value of Encoding is either a number, for predefined
  563.         % encodings, or an array of mixed GIDs and names.
  564.   /Encoding mark Encoding
  565.   DEBUG { (Encoding: ) print dup === flush } if
  566.   dup type /integertype eq {
  567.     StandardEncodings exch get { idname } forall
  568.   } {
  569.     {
  570.       dup type /integertype eq { charset exch get idname } if
  571.     } forall
  572.   } ifelse .packtomark def
  573.         % Construct the CharStrings.
  574.         % Note that they may only correspond to an initial
  575.         % subset of the charset.
  576.   /CharStrings charset length CharStringArray length .min dict def
  577.   DEBUG {
  578.     charset length =only ( charset ) print
  579.     CharStringArray length =only ( CharStringArray) =
  580.     charset == flush
  581.   } if
  582.   0 1 CharStrings maxlength 1 sub {
  583.     dup CharStringArray exch get
  584.     exch charset exch get idstring CharStrings xxput
  585.   } for
  586.   cleanupFont
  587. } bind def
  588.  
  589. % Replace CharStrings with GlyphDirectory for a CIDFont.
  590. /finishCIDFont {    % (currentdict) finishCIDFont -
  591.         % Construct the GlyphDirectory, similar to CharStrings.
  592.   /FDBytes FDArray length 1 gt { 1 } { 0 } ifelse def
  593.   /GlyphDirectory charset length CharStringArray length .min dict def
  594.   DEBUG {
  595.     charset length =only ( charset ) print
  596.     CharStringArray length =only ( CharStringArray) =
  597.     charset == flush
  598.   } if
  599.   0 1 GlyphDirectory maxlength 1 sub {
  600.     dup CharStringArray exch get
  601.         % If there is more than one FDArray entry, add the font
  602.         % index to the beginning of each charstring.
  603.     FDBytes 1 eq {
  604.       FDSelect 2 index get
  605.       1 string dup 0 4 -1 roll put exch concatstrings
  606.     } if
  607.     exch charset exch get GlyphDirectory xxput
  608.   } for
  609.         % Clean up.
  610.   currentdict /FDSelect undef
  611.   cleanupFont
  612. } bind def
  613. % We need to pass the file as a parameter for the sake of the PDF
  614. % interpreter. Also for the sake of PDF, a flag forces the font
  615. % to be defined as <resname> instead of the name embedded in the data.
  616. % This is needed for subsetted fonts; it is valid if the CFF
  617. % contains only a single font.
  618. /StartData {          % <resname> <nbytes> StartData -
  619.   currentfile exch subfilefilter false ReadData
  620. } bind def
  621. /ReadData {           % <resname> <file> <forceresname> ReadData -
  622.  
  623.     % Initialize.
  624.  
  625.   30 dict begin
  626.   /forceresname exch def
  627.   /cff exch def
  628.   /pos 0 def
  629.   /resname exch cvlit def
  630.   /DEBUG DEBUG def    % bring the binding closer
  631.  
  632.     % Read the header.
  633.  
  634.   /f cff def
  635.   /vmajor next def
  636.   /vminor next def
  637.   /hdrsize next def
  638.   /aoffsize next def
  639.  
  640.     % Read the Indexes.
  641.  
  642.   /names Index def
  643.   /topdicts Index def
  644.   /strings Index def
  645.   /gsubrs Index def
  646.  
  647.     % Read the top Dicts.
  648.  
  649.   /offsets 50 dict def
  650.   /queued [] def
  651.   /opdict null def        % reserve a slot
  652.   /fonts [ topdicts {
  653.     0 () /SubFileDecode filter /f exch def
  654.     40 dict begin
  655.         % Preload defaults that differ from PostScript defaults,
  656.         % or that are required.
  657.       /FontType 2 def
  658.       /PaintType 0 def
  659.       /FontMatrix [0.001 0 0 0.001 0 0] def
  660.       /charset StandardCharsets 0 get def
  661.       /Encoding 0 def
  662.       /FontInfo 10 dict
  663.     dup /UnderlinePosition -100 put
  664.     dup /UnderlineThickness 50 put
  665.       def
  666.       /Private 20 dict
  667.     gsubrs length 0 ne { dup /GlobalSubrs gsubrs put } if
  668.       def
  669.       //topdictops Dict
  670.     currentdict end
  671.   } forall ] def
  672.  
  673.     % Read other tables with queued offsets.
  674.  
  675.   DEBUG { (offsets: ) print [ offsets { pop } forall ] == } if
  676.   { /f cff def
  677.     DEBUG { (pos=) print pos = } if
  678.     offsets pos 2 copy .knownget not { pop pop exit } if
  679.     3 1 roll undef
  680.     DEBUG { (exec queued: ) print dup == } if
  681.     exec
  682.   } loop
  683.   offsets length 0 ne {
  684.     (Error: missing tables at ) print [ offsets { pop } forall ] ==
  685.     (Current position is ) print pos ==
  686.     flush stop
  687.   } if
  688.  
  689.     % Process out-of-order tables.
  690.  
  691.   DEBUG { queued length =only ( queued) = flush } if
  692.   queued { exec } forall
  693.  
  694.     % Update Encoding and CharStrings.
  695.  
  696.   fonts {
  697.     begin
  698.     currentdict /CIDFontType known { finishCIDFont } { finishFont } ifelse
  699.     end
  700.   } forall
  701.  
  702.     % Wrap up.
  703.  
  704.   resname mark 0 1 fonts length 1 sub {
  705.     DEBUG { dup =only ( ) print flush } if
  706.     dup names exch get
  707.     forceresname { pop resname } if
  708.     DEBUG { dup == flush } if
  709.     exch fonts exch get
  710.     dup /CIDFontType known {
  711.         % This is a CIDFont.
  712.       dup /CIDFontName 3 index put
  713.       1 index exch /CIDFont defineresource
  714.     } {
  715.         % This is a font.
  716.       dup /FontName 3 index put
  717.       1 index exch definefont
  718.     } ifelse
  719.   } for .dicttomark
  720.   end        % temporary dict
  721.   end        % FontSetInit ProcSet
  722.   /FontSet defineresource pop
  723.  
  724. } bind def
  725.  
  726. % ---------------- Resource category definition ---------------- %
  727.  
  728. currentdict end readonly
  729.  
  730. languagelevel exch 2 .setlanguagelevel
  731.  
  732. /FontSet /Generic /Category findresource dup length dict .copydict
  733. /Category defineresource pop
  734.  
  735. /FontSetInit exch /ProcSet defineresource pop
  736.  
  737. .setlanguagelevel
  738.